package com.zpc.rabbitmq.simple;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.zpc.rabbitmq.util.ConnectionUtil;

/**
 * @Author: ChenYiWen
 * @Date: 2022/1/10
 */
public class DeclareOk {

    private final static String QUEUE_NAME = "simple_queue";

    public static void main(String[] args) throws Exception{
        // 1、获取到连接
        Connection connection = ConnectionUtil.getConnection();
        int asd = connection.getPort();
        // 2、从连接中创建通道，使用通道才能完成消息相关的操作
        Channel channel = connection.createChannel();
        // 3、声明（创建）队列
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);
        AMQP.Queue.DeclareOk declareOk = channel.queueDeclarePassive(QUEUE_NAME);
        //获取队列中的消息个数
        Integer queueCount = declareOk.getMessageCount();
        System.out.println(queueCount);
        channel.close();
        connection.close();
    }
}
